
var auth = []; //路径
var depth = 0;  //树深度，从0开始
var isGo = true; //是否进行下一步

exports.SearchInit = SearchInit
//设置SearchInit
//为deepTraversalForSearch函数的前置条件
function SearchInit(){
  auth = [];
  depth = 0;
  isGo = true;
}

exports.deepTraversalForSearch = deepTraversalForSearch
//设置deepTraversalForSearch
//深度优先遍历--递归写法--用于搜索tree对应节点所在的路径

function deepTraversalForSearch(node,searchValue){
  console.log("depth ------- " + depth++)
  console.log("AuNo ------- " + node.AuNo + "--- searchValue---" + searchValue)
  auth.push(node.AuNo)
  let childrens=node.children;
  console.log("depth ------- " + depth)
  for(let i=0;i<childrens.length;i++){
    deepTraversalForSearch(childrens[i],searchValue);
    if(!isGo){
      return auth
    }
  }

  if(node!=null){
    console.log("AuNo ------- " + node.AuNo)
    console.log("AuNo --- bool ---- " + (node.AuNo === searchValue) )
    if(node.AuNo === searchValue){
      console.log("找到对应值 --- " + auth)
      isGo = false
      return auth
    }else{
      depth--;
      auth.pop();
    }
  }
}
